<template>
  <el-container id="Login">
    <el-main style="position: relative">
      <div
          style="color: white;width: 100%;display: flex;justify-content: center;user-select: none;font-size: 30px;position: absolute;top: 150px">
        <h2>第26届全国广播电视技术能手网络安全专业竞赛</h2>
      </div>
      <el-row justify="center" type="flex">
        <el-col :lg="8" :md="10" :sm="12" :xl="8" :xs="24">

          <div class="main">
            <div class="box" style="position: relative;">
              <h1 style="margin-top: 30px;user-select: none">登录</h1>
              <el-form :model="LoginForm" @keyup.enter.native="Login" style="text-align: center">
                <el-form-item style="margin-top: 10%">
                  <el-input v-model="LoginForm.username" placeholder="用户名" prefix-icon="el-icon-user-solid"
                            style="width: 75%"></el-input>
                </el-form-item>
                <el-form-item style="margin-top: 20px">
                  <el-input v-model="LoginForm.password" type="password" placeholder="密码" prefix-icon="el-icon-unlock"
                            style="width: 75%">
                  </el-input>
                </el-form-item>
                <el-form-item style="margin-top: 20px">
                  <el-button icon="el-icon-s-promotion" type="primary" @click="Login">登录
                  </el-button>
                </el-form-item>
                <div class="registered" style="display: none  ">
                  <a href="/#/registered">注册</a>
                </div>
              </el-form>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      LoginForm: {
        username: '',
        password: ''
      }
    }
  },
  mounted() {
    let res = localStorage.getItem("first_login")
    if (res) {
      console.log("第二次登录")
    } else {
      console.log("第一次登录")
      // 跳转公告页
      this.$router.push("/message")
    }
    this.$axios2.post('/login').then((res) => {
      let code = res.data.code
      if (code === 200) {
        this.$router.push('/task')
      } else {
        console.log('未登录')
      }
    })
  },
  methods: {
    Login() {
      this.$axios1.post('/login', {
        "username": this.LoginForm.username,
        "password": this.LoginForm.password,
      }).then((res) => {
        let data = res.data.code
        if (data === 200) {
          this.$message({
            message: '登录成功',
            type: 'success'
          });
          this.$router.push('/task')
        } else {
          this.$message({
            message: '用户或密码错误',
          });
        }
      })
    }
  }

}
</script>

<style scoped>
::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}

.main {
  min-height: calc(100vh - 40px);
  display: flex;
  color: white;
  justify-content: center;
}

.main .box {
  width: 100%;
  height: 350px;
  margin: auto;
  background-color: #102439;
}

.main .box .registered {
  float: right;
  padding-right: 50px;
}

.main .box .registered a {
  text-decoration: none;
  color: white;
  height: 30px;
  width: 50px;
  line-height: 30px;
  padding-left: 20px;
}

.main .box h1 {
  text-align: center;
}

.title {
  height: 60px;
  width: 200px;
  position: absolute;
  top: -120px;
  left: calc(50% - 115px)
}
</style>